/*
 *  levelUpGame - GameEventHandler.h
 *  Copyright 2011 W. Reckman. All rights reserved.
 */
#ifndef GAME_EVENT_HANDLER_H
#define GAME_EVENT_HANDLER_H

#include "ofEvents.h"
#include "Ghost.h"
#include "Pickup.h"
#include "Player.h"

class Settings;
class LevelUpApp;
class GameModel;

//NOTE: uncomment this to enable player ID sounds when they try to move while in precount stage
#define ENABLE_SOUND_ON_PRECOUNT_MOVE

//NOTE: these defines determine at which point(s) new players will be requested
#define REQUEST_PLAYERS_ON_GAME_START
//#define REQUEST_PLAYERS_ON_GAME_END_SEQUENCE

//NOTE: uncomment this to request new players on init immediately
//#define REQUEST_NEW_PLAYERS_ON_INIT

//NOTE: uncomment this to have 10 second-precount sound randomized between 'get ready' and 'take your positions' sounds
#define RANDOMIZE_10SEC_PRECOUNT_SOUND

//--------------------------------------------------------------
class EventArgsGame {
public:
	enum GAME_OBJECT_TYPE { GOT_PLAYER, GOT_GHOST, GOT_PICKUP };
	enum GAME_EVENT_TYPE {
		GE_NEW_FRAME, GE_GAME, GE_PLAYER,
		GE_PLAYER_QUEUED, GE_OCREATED, GE_ODESTROYED
	};
	
	enum GAME_EVENT_SUBTYPE {
		GES_GAME_INIT, GES_GAME_BALANCE_CHANGED,												/* for GE_GAME */
		GES_GAME_PRECOUNT_TICK, GES_GAME_STATE,
		
		GES_PLAYER_TURN, GES_PLAYER_UNFREEZE,														/* for GE_PLAYER */
		GES_PLAYER_CORPOREALIZE, GES_PLAYER_PRECOUNT_MOVE_ATTEMPT
	};
	
	union GameObject {
		Ghost* ghost;
		Pickup* pickup;
		Player* player;
	};
	
	
	enum GAME_EVENT_TYPE eventType;
	enum GAME_EVENT_SUBTYPE eventSubtype;
	enum GAME_OBJECT_TYPE objType;
	enum GAME_OBJECT_TYPE causeType;
	
	GameObject obj;
	GameObject cause;
	int intVal;
	float floatVal;
	GAME_STATE prevState, currState;
};


//--------------------------------------------------------------
class GameEventHandler {
public:
	EventArgsGame argsGameEvent;
	ofEvent<EventArgsGame> gameEvent;
	
	
	explicit GameEventHandler( LevelUpApp& appRef_ );
	void setup();
	
	void onGameEvent( EventArgsGame& ev_ );
	
private:
	LevelUpApp& appRef;
	GameModel& game;
	Settings& s;
	
	float turnMinPitch, turnMaxPitch;
	int maxNumPickups;
	float playerNoHitTime;
	float gamePrecountTime;
	float gameStartNoHitTime;
	float endSequenceAnimTime;
	float endSequenceDisplayTime;
	bool resetPlayerOnGhostHit;
	int startTextShowTime;
	
	void handleGameEvent( EventArgsGame& ev_ );
	void handleGameStateChange( EventArgsGame& ev_ );
	void handlePlayerEvent( EventArgsGame& ev_ );
	
	void logGameEvent( EventArgsGame& ev_ );
};

#endif /* ! GAME_EVENT_HANDLER_H */
